package com.uls.web.controller.questionnaire;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.questionnaire.domain.Surveyrules;
import com.uls.questionnaire.service.ISurveyrulesService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 问卷规则设置Controller
 * 
 * @author zxh
 * @date 2024-11-09
 */
@RestController
@RequestMapping("/questionnaire/surveyrules")
public class SurveyrulesController extends BaseController
{
    @Autowired
    private ISurveyrulesService surveyrulesService;

    /**
     * 查询问卷规则设置列表
     */
    @PreAuthorize("@ss.hasPermi('questionnaire:surveyrules:list')")
    @GetMapping("/list")
    public TableDataInfo list(Surveyrules surveyrules)
    {
        startPage();
        List<Surveyrules> list = surveyrulesService.selectSurveyrulesList(surveyrules);
        return getDataTable(list);
    }

    /**
     * 导出问卷规则设置列表
     */
    @PreAuthorize("@ss.hasPermi('questionnaire:surveyrules:export')")
    @Log(title = "问卷规则设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Surveyrules surveyrules)
    {
        List<Surveyrules> list = surveyrulesService.selectSurveyrulesList(surveyrules);
        ExcelUtil<Surveyrules> util = new ExcelUtil<Surveyrules>(Surveyrules.class);
        util.exportExcel(response, list, "问卷规则设置数据");
    }

    /**
     * 获取问卷规则设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('questionnaire:surveyrules:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(surveyrulesService.selectSurveyrulesByRuleId(ruleId));
    }

    /**
     * 新增问卷规则设置
     */
    @PreAuthorize("@ss.hasPermi('questionnaire:surveyrules:add')")
    @Log(title = "问卷规则设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Surveyrules surveyrules)
    {
        return toAjax(surveyrulesService.insertSurveyrules(surveyrules));
    }

    /**
     * 修改问卷规则设置
     */
    @PreAuthorize("@ss.hasPermi('questionnaire:surveyrules:edit')")
    @Log(title = "问卷规则设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Surveyrules surveyrules)
    {
        return toAjax(surveyrulesService.updateSurveyrules(surveyrules));
    }

    /**
     * 删除问卷规则设置
     */
    @PreAuthorize("@ss.hasPermi('questionnaire:surveyrules:remove')")
    @Log(title = "问卷规则设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(surveyrulesService.deleteSurveyrulesByRuleIds(ruleIds));
    }
}
